package com.briup;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;


public class DruidTest {
    @Test
    public void test() {
        Connection conn = null;
        // 1. 加载配置文件
        Properties properties = new Properties();
        InputStream iStream = DruidTest.class.getClassLoader().getResourceAsStream("druid.properties");
        try {
            properties.load(iStream);
            // properties.forEach((k, v) -> System.out.println(k + ":" + v));
            // 2. 获取连接池对象
            DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
            conn = dataSource.getConnection();
            System.out.println("conn: " + conn);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

}
